<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.autocomplete.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.autocomplete.js"></script>
<script type="text/javascript">
Refresh = function(){
	//jq的自动完成
	$(".ajax_product").autocomplete("<?=url('Storage::Product/ProductInfoAjax')?>").result(function(event, data, formatted){
		if (data[0])
		{
			var container = $(this).parent().parent();
			container.find("input.product_number").val(data['number']);
			container.find("input[name^='product_id']").val(data['id']);
			container.find("input[name^='default_price']").val(data['cost_price']);
			container.find("input[name^='cost_price']").val(data['cost_price']);
		}
	});
};
$(function(){
	var i = 0;
	$("#add_product").click(function(){
		var _html = "<tr>";
		_html += "<td><input type='text' size='60' name='product_number_new" + i + "' class='ajax_product' /><input type='hidden' name='product_id_new" + i + "' /></td>";
		_html += "<td><input type='text' size='8' disabled='disabled' name='default_price_new" + i + "' /></td>";
		_html += "<td><input type='text' size='8' name='cost_price_new" + i + "' /></td>";
		_html += "<td><input type='text' size='8' name='quantity_new" + i + "' /></td>";
		_html += "<td><a href='javascript:void(0);' class='del_product'>删除产品</a></td>";
		_html += "</tr>";
		$("#list").append(_html);
		Refresh();
		i++;
	});
	$(".del_product").live("click", function(){
		if ( ! confirm("确定删除该产品？"))
		{
			return false;
		}
		else
		{
			$(this).parent().parent().remove();
		}
	});
	$("#add_save").submit(function(){
		if (! confirm("是否添加入库单？"))
		{
			return false;
		}
		 $("#submit").attr("disabled","disabled");
	});
	Refresh();
});
</script>
<form method="post" action="<?=url('Storage::OtherIO/InCreateSave')?>" id="add_save">
<table class="form_table">
<tr>
	<th>经手人员</th>
	<td>
		<select name="user_id">
			<?foreach ($user as $u):?>
			<option value="<?=$u['id']?>" <?if($u['id']==CURRENT_USER_ID)echo "selected='selected'"?>><?=$u['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>选择仓库</th>
	<td>
		<select name="warehouse_id" id="warehouse">
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?if(isset($warehouse_id) && $warehouse_id == $w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>备注</th>
	<td colspan="2"><textarea name="notes" cols="50" rows="2"></textarea></td>
</tr>
</table>
<table width="80%" class="list_table" id="list">
<tr>
	<th width="400">产品编号</th>
	<th width="80">默认成本</th>
	<th width="80">单位成本</th>
	<th width="80">数量</th>
	<th width="100">操作</th>
</tr>
<?if (isset($item)):?>
<?foreach ($item as $key => $i):?>
<tr>
	<td>
		<input type="text" size="60" name="product_number_new<?=$key?>" class="ajax_product" value="<?=$i['number']?> <?=$i['name']?>" />
		<input type="hidden" name="product_id_new<?=$key?>" value="<?=$i['product_basic_id']?>" />
	</td>
	<td><input type="text" size="8" disabled="disabled" name="default_price_new<?=$key?>" value="<?=sprintf('%.2f', $i['cost_price'])?>" /></td>
	<td><input type="text" size="8" name="cost_price_new<?=$key?>" value="<?=sprintf('%.2f', $i['cost_price'] * $discount / 10)?>" /></td>
	<td><input type="text" size="8" name="quantity_new<?=$key?>" value="<?=$i['quantity']?>" /></td>
	<td><a href="javascript:void(0);" class="del_product">删除产品</a></td>
</tr>
<?endforeach;?>
<?endif;?>
</table>
<a id="add_product">添加入库单产品</a>
<div align="center"><input id="submit" type="submit" class="button" value="添加订单" /><input type="hidden" name="<?=Q::ini('unique_token_name');?>" value="<?=Helper_BSS_Normal::genToken();?>"/></div>
</form>
<?php $this->_endblock();?>